home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / mbb35src / 8530tmr.asm < prev    next >
Encoding:
Assembly Source File  |  1987-11-11  |  9.3 KB  |  215 lines

  1. ;==========================================================================;
  2. ; Timer service for the 8530                                               ;
  3. ;                                                                          ;
  4. ;   Copyright 1986, 1987 by H. Roy Engehausen.  All rights reserved.       ;
  5. ;   This software may be freely distributed and used, but it may not       ;
  6. ;   under any circumstances be sold by anyone other than the author.       ;
  7. ;   It may be distributed by a commercial company as long as it is         ;
  8. ;   for no cost.                                                           ;
  9. ;                                                                          ;
  10. ;   Permission is explicity granted to use this code as a model for        ;
  11. ;   other programs requiring interrupt driven serial I/O as long as they   ;
  12. ;   carry this copyright notice and the imbedded constants                 ;
  13. ;                                                                          ;
  14. ;     Inputs:  SI = COM block                                              ;
  15. ;==========================================================================;
  16.  
  17. ;--------------------------------------------------------------------------;
  18. ; Transmitter on?   If so go check it                                      ;
  19. ;--------------------------------------------------------------------------;
  20.  
  21.         TEST    flags[SI],flags_xmt_on ; Transmitter on?
  22.         JNZ     tmr_8530_tx_on
  23.  
  24. ;--------------------------------------------------------------------------;
  25. ; If full duplex, ignore the DCD check                                     ;
  26. ;--------------------------------------------------------------------------;
  27.  
  28.         TEST    options[SI],opt_fd  ; Full duplex?
  29.         JNZ     tmr_8530_fd_on
  30.  
  31. ;--------------------------------------------------------------------------;
  32. ; Zero the slot timer?  If so, do it and then we are done                  ;
  33. ;--------------------------------------------------------------------------;
  34.  
  35.         TEST    flags[SI],flags_dcd_on ; DCD on?
  36.         JZ      tmr_8530_no_dcd     ;      Nope
  37.  
  38.         MOV     timer_dcd[SI],0     ; Zero the timer since DCD is on
  39.  
  40.         JMP     tmr_8530_done       ; All done
  41.  
  42. ;--------------------------------------------------------------------------;
  43. ; Slot timer running.  Increment as needed and check for slot to be done   ;
  44. ;--------------------------------------------------------------------------;
  45.  
  46. tmr_8530_no_dcd:
  47.  
  48.         MOV     AX,timer_dcd[SI]    ; Get timer
  49.  
  50.         CMP     AL,value_slot[SI]   ; Slot expired?
  51.         JAE     tmr_8530_slot_over  ;      Yes...
  52.         JMP     tmr_8530_no_slot    ;      Nope
  53.  
  54. ;--------------------------------------------------------------------------;
  55. ; Slot complete.  See if P lets us thru?                                   ;
  56. ;--------------------------------------------------------------------------;
  57.  
  58. tmr_8530_slot_over:                 ;
  59.  
  60.         CALL    random              ; Get a random number
  61.         CMP     AL,value_p[SI]      ; Check against "P" (the probability)
  62.         JBE     tmr_8530_fd_on      ; Send it!
  63.  
  64.         MOV     timer_dcd[SI],0     ; Zero the timer to get to next slot
  65.         JMP     tmr_8530_done       ; All done
  66.  
  67. ;--------------------------------------------------------------------------;
  68. ; We have either satisfied P/slot or this is a full duplex                 ;
  69. ; link.  See if any output pending so we can send it.                      ;
  70. ;--------------------------------------------------------------------------;
  71.  
  72. tmr_8530_fd_on:                     ;
  73.  
  74.         CMP     buffer_t_a[SI],0    ; Is there a transmit buffer?
  75.         JNZ     tmr_8530_start_t    ;      Yes.. We need to start the xmtr
  76.         JMP     tmr_8530_done       ;      No... All done
  77.  
  78. ;--------------------------------------------------------------------------;
  79. ; Turn on transmitter                                                      ;
  80. ;--------------------------------------------------------------------------;
  81.  
  82. tmr_8530_start_t:                   ;
  83.  
  84.         MOV     DX,baseaddr[SI]     ; Get port address
  85.         CALL    ton_clk_8530        ; Call the routine
  86.  
  87.         JMP     tmr_8530_done       ; All done
  88.  
  89. ;--------------------------------------------------------------------------;
  90. ; Increment DCD counter and exit                                           ;
  91. ;--------------------------------------------------------------------------;
  92.  
  93. tmr_8530_no_slot:
  94.  
  95.         INC     AX
  96.         MOV     timer_dcd[SI],AX    ; Bump timer
  97.         JMP     tmr_8530_done       ; All done
  98.  
  99. ;--------------------------------------------------------------------------;
  100. ; Transmitter is on.  See what timing period we are in and take action     ;
  101. ;--------------------------------------------------------------------------;
  102.  
  103. tmr_8530_tx_on:
  104.  
  105.         MOV     AX,timer_xmtr[SI]   ; Get xmtr time value
  106.         INC     AX                  ; Bump up
  107.  
  108.         SUB     BH,BH               ; Clear top of register
  109.         MOV     BL,period_xmtr[SI]  ; Get time period
  110.  
  111.         JMP     CS:tmr_8530_table[BX] ; Go do routine
  112.  
  113. tmr_8530_table LABEL WORD            ;
  114.         DW      OFFSET tmr_8530_txd  ; 0 = Waiting for TXD
  115.         DW      OFFSET tmr_8530_done ; 2 = Transmitter running, ignore
  116.         DW      OFFSET tmr_8530_crc  ; 4 = Waiting for CRC to finish
  117.  
  118. ;--------------------------------------------------------------------------;
  119. ; Waiting for TXD to terminate                                             ;
  120. ;--------------------------------------------------------------------------;
  121.  
  122. tmr_8530_txd:                       ;
  123.  
  124.         CMP     AX,value_txd[SI]    ; TXD done?
  125.         JBE     tmr_8530_xmtr_done  ;      No..  Don't do anything
  126.  
  127. ;--------------------------------------------------------------------------;
  128. ; TXD complete ..  start sending a packet                                  ;
  129. ;--------------------------------------------------------------------------;
  130.  
  131. tmr_8530_start_packet:
  132.  
  133.         MOV     buffer_t_out[SI],0  ; Set buffer pointer to 0 since we are
  134.                                     ;      about to send first character
  135.                                     ;      and this points to character sent!
  136.  
  137.         MOV     period_xmtr[SI],period_x_tx ; Event = sending data
  138.  
  139.         MOV     DX,baseaddr[SI]     ; Get chip address
  140.  
  141.         CALL    int_8530            ; Change interrupt mask as needed
  142.  
  143.         MOV     AL,rst_tcrc         ; Reset XMTR CRC
  144.         OUT     DX,AL               ;
  145.  
  146.         MOV     ES,buffer_t_a[SI]   ; Get buffer address
  147.         MOV     AL,ES:0             ; Get first character
  148.  
  149.         OR      DL,scc_data_mask    ; Get the data port address
  150.         OUT     DX,AL               ; Send the character
  151.         AND     DL,0FFH-scc_data_mask ; Convert back to control address
  152.  
  153.         MOV     AL,rst_eom          ; Reset Underrun, End of Frame Flag
  154.         OUT     DX,AL               ;
  155.  
  156.         SUB     AX,AX               ; Set transmitter timer to zero
  157.  
  158.         JMP     tmr_8530_xmtr_done  ; All done
  159.  
  160. ;--------------------------------------------------------------------------;
  161. ; Packet complete.  This waits for the CRC to be sent.  The 8530 has no    ;
  162. ; way of telling us when the packet is finished being sent so we wait      ;
  163. ; some amount of time before continuing.  This is based on the speed.      ;
  164. ;--------------------------------------------------------------------------;
  165.  
  166. tmr_8530_crc:                       ;
  167.  
  168.         CMP     AX,value_crc[SI]    ; TXD done?
  169.         JBE     tmr_8530_xmtr_done  ;      No..  Don't do anything
  170.  
  171. ; See if more packets are pending.  If so, we don't need TXD so just start
  172. ; sending.  The buffer just sent has already been dequeued in the
  173. ; interrupt handler
  174.  
  175.         CMP     buffer_t_a[SI],0    ; Any buffers there?
  176.         JZ      tmr_8530_crc_nomore ;      Nope.. Finish up
  177.         JMP     tmr_8530_start_packet ;    Yep.. Send the packet
  178.  
  179. tmr_8530_crc_nomore:                ;
  180.  
  181. ; CRC complete -- turn transmitter off!
  182.  
  183.         MOV     DX,baseaddr[SI]     ; Get chip address
  184.         MOV     AL,sccreg5          ; WR5
  185.         OUT     DX,AL               ;
  186.         MOV     AL,dtr_pin+tx_8bits+tx_crcen ; DTR+8bits+crc
  187.         OUT     DX,AL               ;
  188.  
  189.         AND     flags[SI],0FFH-flags_xmt_on-flags_tbe ; Transmitter now off
  190.  
  191.         TEST    options[SI],opt_fd  ; Full duplex?
  192.         JNZ     tmr_8530_crc_fd     ;      Yes.. No clock changes
  193.  
  194.         CALL    ron_clk_8530        ; Enable receiver and clock
  195.         JMP     tmr_8530_done       ; All done
  196.  
  197. tmr_8530_crc_fd:
  198.  
  199.         CALL    ron_8530            ; Enable receiver but not clock
  200.         JMP     tmr_8530_done       ; All done
  201.  
  202. ;--------------------------------------------------------------------------;
  203. ; Transmitter timer functions done.  Set the transmitter timer             ;
  204. ;--------------------------------------------------------------------------;
  205.  
  206. tmr_8530_xmtr_done:                 ;
  207.  
  208.         MOV     timer_xmtr[SI],AX       ; Set transmitter value
  209.  
  210. ;--------------------------------------------------------------------------;
  211. ; All timer functions for 8530 are done                                    ;
  212. ;--------------------------------------------------------------------------;
  213.  
  214. tmr_8530_done:
  215.